// Name：P3_1.c
// Purpose：显示矩阵
// Author：wjy
// From：《C语言程序设计：现代方法》（第二版）第三章第5题
// Date：2021.12.30

#include <stdlib.h>
#include <stdio.h>

int main(void)
{
    int nums[4][4];
    int sum = 0;
    printf("Enter the numbers from 1 to 16 in any order:\n");
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            scanf("%d", &nums[i][j]);
        }
    }
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            printf("%2d ", nums[i][j]);
        }
        printf("\n");
    }

    printf("Row sums:");
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            sum = sum + nums[i][j];
        }
        printf(" %d", sum);
        sum = 0;
    }
    printf("\n");

    printf("Column sums:");
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            sum = sum + nums[j][i];
        }
        printf(" %d", sum);
        sum = 0;
    }
    printf("\n");

    printf("Diagonal sums: ");
    printf(" %d %d\n", nums[0][0] + nums[1][1] + nums[2][2] + nums[3][3], nums[0][3] + nums[1][2] + nums[2][1] + nums[3][0]);

    system("pause");
    return 0;
}